package com.shop.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author
 */
@WebServlet("/code")
public class CodeController extends BaseServlet {
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //  创建验证码工具类   param为宽 高 字符数  字符长度
        ValidateCode validateCode = new ValidateCode(100,30,4,6);
       //获取验证码
        String code =validateCode.getCode();
        //  获取验证码字符串内容
        request.getSession().setAttribute("code",code);
        //将验证码内容通过流向页面输出
        validateCode.write(response.getOutputStream());
    }
}
